<template lang="pug">
  kalix-dialog.user-add(title='添加' bizKey="lives" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" )
    div.el-form(slot="dialogFormSlot")
      el-form-item.short(label="直播分类" prop="type" v-bind:label-width="labelWidth" v-bind:rules="rules.type" )
        kalix-select(v-model="formModel.type"  v-bind:requestUrl="requestUrl" id="name" appName="classifyname" placeholder="请选择直播类别")
      el-form-item.short(label="直播人id" prop="userId" v-bind:label-width="labelWidth" v-bind:rules="rules.userId" class="none" )
        el-input(v-model="formModel.userId" @keyup.native="proving")
      el-form-item.short(label="直播人名" prop="userName" v-bind:label-width="labelWidth" v-bind:rules="rules.userName")
        <!--el-input(v-model="formModel.userName")-->
        el-select(v-model="formModel.userId" placeholder="请选择" @change="getUid")
          el-option(v-for="item in options" v-bind:key="item.id" v-bind:label="item.name" v-bind:value="item.id")
      el-form-item.short(label="直播流地址" prop="liveUrl" v-bind:label-width="labelWidth" v-bind:rules="rules.liveUrl")
        el-input(v-model="formModel.liveUrl" readonly)
      el-form-item.short(label="直播封面图片" prop="imgUrl" v-bind:label-width="labelWidth")
        kalix-clansman-upload(:action="action" v-on:filePath="getFilePath" fileType="img" tipText="只能上传jpg/png文件")
      <!--el-form-item.short(label="图片封面地址" prop="imgUrl" v-bind:label-width="labelWidth" v-bind:rules="rules.imgUrl")-->
        <!--el-input(v-model="formModel.imgUrl")-->
      el-form-item.short(label="直播间ID" prop="liveId" v-bind:label-width="labelWidth" v-bind:rules="rules.liveId" class="none" )
        el-input(v-model="formModel.liveId" @keyup.native="proving1")
      el-form-item.short(label="直播间名称" prop="liveName" v-bind:label-width="labelWidth" v-bind:rules="rules.liveName")
        el-input(v-model="formModel.liveName")
      <!--el-form-item.short(label="开播时间" prop="startTime" v-bind:label-width="labelWidth" v-bind:rules="rules.startTime")-->
        <!--el-input(v-model="formModel.startTime")-->
      <!--el-form-item.short(label="结束时间" prop="endTime" v-bind:label-width="labelWidth" v-bind:rules="rules.endTime")-->
        <!--el-input(v-model="formModel.endTime")-->
      <!--el-form-item.short(label="直播状态0，开播1，关闭直播" prop="state" v-bind:label-width="labelWidth" v-bind:rules="rules.state")-->
        <!--el-input(v-model="formModel.state")-->
      el-form-item(label="直播状态" prop="state")
        el-radio-group(v-model="formModel.state")
          el-radio(label="开播" value="开播")
          el-radio(label="闭播" value="闭播")
</template>

<script type="text/ecmascript-6">
  import {LivesURL, ClassifyURL, LiveRoomsURL} from '../../config.toml'
  import FormModel from './model'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  export default {
    name: 'LivesAdd',
    components: {KalixSelect, KalixClansmanUpload},
    data() {
      return {
        requestUrl: ClassifyURL,
        formModel: Object.assign({}, FormModel),
        action: baseURL + '/camel/rest/upload',
        labelWidth: '170px',
        rules: {
          // imgUrl: [{required: true, message: '请输入坐班医生', trigger: 'change'}]
        },
        targetURL: LivesURL,
        options: []
      }
    },
    mounted() {
      this.getUname()
    },
    methods: {
      getUname() {
        this.axios.request({
          method: 'GET',
          url: '/camel/rest/users'
        }).then(res => {
          console.log('res========', res.data)
          this.options = res.data.data
        })
      },
      getUid(val) {
        let obj = {}
        obj = this.options.find((item) => {
          return item.id === val
        })
        this.formModel.userName = obj.name
        console.log('bbbbbbbbbbbbbbbbbbbbbb', this.formModel.userName)
        this.getLiveUrl(val)
      },
      getLiveUrl(uid) {
        this.axios.get(LiveRoomsURL, {
          params: {
            jsonStr: {'userId': uid}
          }
        }).then(res => {
          console.log('aaa', res.data)
          if (res.data.totalCount > 0) {
            this.formModel.liveUrl = res.data.data[0].liveUrl
          } else {
            this.formModel.liveUrl = null
          }
        })
      },
      proving() {
        this.formModel.userId = this.formModel.userId.replace(/[^\d]/g, '')
        this.formModel.userId = this.formModel.userId.replace('.', '')
      },
      proving1() {
        this.formModel.liveId = this.formModel.liveId.replace(/[^\d]/g, '')
        this.formModel.liveId = this.formModel.liveId.replace('.', '')
      },
      init(dialogOption) {
        console.log('---------dialogOption------------', dialogOption)
      },
      getFilePath(filePath, fileName) {
        console.log('--getFilePath---', filePath)
        console.log('--fileName---', fileName)

        this.formModel.imgUrl = filePath
        this.formModel.imgName = fileName
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 110%
    .el-select
      width 110%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
    .none
        display none

</style>
